package com.ecric.http.webView;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.ecric.http.R;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Eric
 * <h3>Date</h3> 2017/9/21 16:14
 * <h3>Copyright</h3> Copyright (c)2017 Shenzhen TLKY  Co., Ltd. Inc. All rights reserved.
 */
public class MyObject {
    Context context;
    public MyObject(Context context) {
        this.context = context;
    }
    /**
     * 需要被JS调用的方法必须得使用JavascriptInterface类进行注解,否则是无法被调用的
     * @param content
     */
    @JavascriptInterface
    public void showToast(String content){
        Toast.makeText(context, content, Toast.LENGTH_SHORT).show();
    }

    @JavascriptInterface
    public void showList(){
        final String[] items = new String[]{"计算机维护","Java","计算机组成原理"};
        new AlertDialog.Builder(context).setTitle("图书列表").setIcon(R.mipmap.ic_launcher)
                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(context, items[which], Toast.LENGTH_SHORT).show();
                    }
                }).setPositiveButton("确定" ,null).create().show();
    }

}
